package com.ruoyi.project.article.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.project.article.domain.Article;
import com.ruoyi.project.article.mapper.ArticleMapper;
import com.ruoyi.project.article.service.IArticleService;

/**
 * 文章调度信息 服务层
 * 
 * @author ruoyi
 */
@Service
public class ArticleServiceImpl implements IArticleService
{

    @Autowired
    private ArticleMapper articleMapper;

    /**
     * 获取quartz调度器的计划任务列表
     * 
     * @param article 调度信息
     * @return
     */
    @Override
    public List<Article> selectArticleList(Article article)
    {
        return articleMapper.selectArticleList(article);
    }

    /**
     * 通过调度任务ID查询调度信息
     * 
     * @param id 文章ID
     * @return 调度任务对象信息
     */
    @Override
    public Article selectArticleById(Long id)
    {
        return articleMapper.selectArticleById(id);
    }

    /**
     * 删除任务后，所对应的trigger也将被删除
     * 
     * @param article 调度信息
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteArticle(Long id) 
    {
        int rows = articleMapper.deleteArticleById(id);
        System.out.println("fx deleteArticle rows="+rows);
        
        return rows;
    }

    /**
     * 批量删除调度信息
     * 
     * @param articleIds 需要删除的任务ID
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteArticleByIds(Long[] articleIds) 
    {
        for (Long id : articleIds)
        {
        	System.out.println("fx deleteArticleByIds id="+id);
//            Article article = articleMapper.selectArticleById(id);
            deleteArticle(id);
        }
    }

    /**
     * 新增任务
     * 
     * @param article 调度信息 调度信息
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertArticle(Article article) 
    {
        int rows = articleMapper.insertArticle(article);
        return rows;
    }

    /**
     * 更新任务的时间表达式
     * 
     * @param article 调度信息
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateArticle(Article article) 
    {
        int rows = articleMapper.updateArticle(article);
        System.out.println("fx article updateArticle rows="+rows);
        return rows;
    }

}